package com.example.admin.yuejian21.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.admin.yuejian21.Bean.Activity;
import com.example.admin.yuejian21.Bean.AskList;
import com.example.admin.yuejian21.R;
import com.example.admin.yuejian21.activity.ActivityDetailActivity;
import com.example.admin.yuejian21.activity.MasterDetailActivity;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Administrator on 2017/10/16 0016.
 */

public class ProblemAdapter extends RecyclerView.Adapter {
    private Context mContext;

    private List mDataList;//数据存储
    private LayoutInflater mLayoutInflater;//准备布局

    public ProblemAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_master_wt, parent, false);
        return new com.example.admin.yuejian21.Adapter.ProblemAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final AskList entity = (AskList) mDataList.get(position);
        if (null == entity)
            return;
        com.example.admin.yuejian21.Adapter.ProblemAdapter.ViewHolder viewHolder = (com.example.admin.yuejian21.Adapter.ProblemAdapter.ViewHolder) holder;
        viewHolder.wt_name.setText(entity.getUser_id());
        viewHolder.wt.setText(entity.getQuestion());
        viewHolder.answer_name.setText(entity.getMaster_id());
        viewHolder.answer.setText(entity.getAnswer());

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,MasterDetailActivity.class);
                intent.putExtra("id",entity.getId());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView wt_name,wt,answer_name,answer;
        LinearLayout dashi_container;

        public ViewHolder(View itemView) {
            super(itemView);
            dashi_container = (LinearLayout) itemView.findViewById(R.id.dashi_container);
            wt_name = (TextView) itemView.findViewById(R.id.wt_name);
            wt = (TextView) itemView.findViewById(R.id.wt);
            answer_name = (TextView) itemView.findViewById(R.id.answer_name);
            answer = (TextView) itemView.findViewById(R.id.answer);

        }
    }
}
